
package ch.hearc.coursJava.IO.RMI.exemple0.pcA.moo;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.rmi.RemoteException;
import java.util.Date;

import com.bilat.tools.reseau.rmi.RmiTools;

public class Horloge implements Horloge_I
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public Horloge() throws RemoteException
		{
		RmiTools.shareObject(this, PORT, ID);
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	@Override
	public Date getTime()
		{
		return new Date(System.currentTimeMillis());
		}

	@Override
	public String toString()
		{
		return getTime().toString();
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/
	private static InetAddress createInetAdress()
		{
		try
			{
			return InetAddress.getByName("157.26.88.119");
			}
		catch (UnknownHostException e)
			{
			e.printStackTrace();
			return null;
			}
		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/
	/*------------------------------*\
	|*			  Static			*|
	\*------------------------------*/
	public static final int PORT = RmiTools.getPortDefaultRMI();
	public static final InetAddress IP = createInetAdress();
	public static final String ID = "HorlogeID";
	}
